package com.nondo.rdp.auth.domain.base;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.nondo.rdp.auth.domain.User;
import com.nondo.rdp.core.domain.base.BaseEntity;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.LastModifiedBy;

import javax.persistence.*;

import java.io.Serializable;

/**
 * 数据Entity类
 *
 * @author slacrey
 * @version 2013-05-28
 */
@MappedSuperclass
public abstract class DataEntity extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    protected Long companyId; //公司编号
    protected User createBy;    // 创建者
    protected User updateBy;    // 更新者

    public DataEntity() {
        super();
    }

    @Column(name = "company_id")
    public Long getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Long companyId) {
        this.companyId = companyId;
    }

    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "create_by", nullable = true)
    @CreatedBy
    public User getCreateBy() {
        return createBy;
    }

    public void setCreateBy(User createBy) {
        this.createBy = createBy;
    }


    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "update_by", nullable = true)
    @LastModifiedBy
    public User getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(User updateBy) {
        this.updateBy = updateBy;
    }


}
